package com.chevic.util;

import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
	/**
	 * 返回yyyy-MM-dd HH:mm:ss格式的字符串
	 * @return
	 */
	public static String getCurrentTime(){
		String time = "" ;
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		time = df.format(new Date());// new Date()为获取当前系统时间

		return time ;
	}
	
	/**
	 * sha-1 加密
	 * @param sourceString
	 * @return
	 */
    public static String SHA1Encode(String sourceString) {  
        String resultString = null;  
        try {  
           resultString = new String(sourceString);  
           MessageDigest md = MessageDigest.getInstance("SHA-1");  
           resultString = byte2hexString(md.digest(resultString.getBytes()));  
        } catch (Exception ex) {  
        }  
        return resultString;  
    }  
    
    private static String byte2hexString(byte[] bytes) {  
        StringBuffer buf = new StringBuffer(bytes.length * 2);  
        for (int i = 0; i < bytes.length; i++) {  
            if (((int) bytes[i] & 0xff) < 0x10) {  
                buf.append("0");  
            }  
            buf.append(Long.toString((int) bytes[i] & 0xff, 16));  
        }  
        return buf.toString().toUpperCase();  
    }  

}
